import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/cabinet/views/cabinet_list_header.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_scrollView.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_button.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_card.dart';
import 'logic.dart';

class CabinetListInfoEditPage extends StatefulWidget {
  const CabinetListInfoEditPage({Key? key}) : super(key: key);

  @override
  State<CabinetListInfoEditPage> createState() => _CabinetListInfoEditPageState();
}

class _CabinetListInfoEditPageState extends State<CabinetListInfoEditPage> {
  final CabinetListInfoEditLogic logic = Get.put(CabinetListInfoEditLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(navigationTitle: "指定快递员"),
      body: HLScrollView(padding: EdgeInsets.only(left: 16, right: 16, top: 12), children: [
        MGCard(
          children: [
            CabinetListHeader(
              deviceID: logic.infoModel.tmcDevices?.disPlayNo ?? "",
              deviceName: logic.infoModel.tmcDevices?.deviceAddress ?? "",
              showBottom: false,
            )
          ],
        ),
        MGCard(
          margin: EdgeInsets.only(top: 16),
          padding: EdgeInsets.only(left: 16, right: 16, top: 24, bottom: 24),
          children: [
            Container(
              child: Text(
                "柜机编号：${String.fromCharCode((logic.infoModel.boardNo ?? 0) + 65)}",
                textAlign: TextAlign.start,
                style: TextStyle(color: MGColors.text1Color, fontSize: MGFont.textFont1),
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 24),
              padding: EdgeInsets.only(left: 10, right: 10),
              decoration: BoxDecoration(color: MGColors.splitColor, borderRadius: BorderRadius.circular(6)),
              child: TextField(
                controller: logic.controller,
                style: TextStyle(color: MGColors.text1Color, fontSize: MGFont.textFont1),
                keyboardType: TextInputType.phone,
                decoration: InputDecoration(
                  enabledBorder: UnderlineInputBorder(borderSide: BorderSide.none),
                  focusedBorder: UnderlineInputBorder(borderSide: BorderSide.none),
                  hintText: "请输入快递员手机号",
                  hintStyle: TextStyle(color: MGColors.text4Color, fontSize: MGFont.textFont1),
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 24),
              child: Row(
                children: [
                  Text(
                    "激活状态:",
                    textAlign: TextAlign.start,
                    style: TextStyle(
                      color: MGColors.text1Color,
                      fontSize: MGFont.textFont1,
                    ),
                  ),
                  Obx(() => _chooseWidget(
                        title: "启用",
                        isAction: logic.isAction.value,
                        action: () {
                          logic.isAction.value = !logic.isAction.value;
                        },
                      )),
                  Obx(() => _chooseWidget(
                        title: "禁用",
                        isAction: !logic.isAction.value,
                        action: () {
                          logic.isAction.value = !logic.isAction.value;
                        },
                      )),
                ],
              ),
            ),
            MGButton(
              title: "确认",
              margin: EdgeInsets.only(top: 30),
              buttonAction: logic.sureAction,
            )
          ],
          crossAxisAlignment: CrossAxisAlignment.start,
        )
      ]),
    );
  }

  Widget _chooseWidget({required String title, bool isAction = true, Function()? action}) {
    return InkWell(
      child: Container(
        padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
        child: Row(
          children: [
            Text(title,
                style: TextStyle(
                  color: MGColors.text2Color,
                  fontSize: MGFont.textFont1,
                )),
            SizedBox(width: 10),
            Image.asset(isAction ? MGImage.image("public_pass") : MGImage.image("public_no_pass"), width: 20),
          ],
        ),
      ),
      onTap: action,
    );
  }

  @override
  void dispose() {
    Get.delete<CabinetListInfoEditLogic>();
    super.dispose();
  }
}
